package com.shard.knabejay.birthday;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by KnabeJay on 16/5/6.
 */
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
    private static final String TAG = "MyAdapter";
    Context mcontext;
    public ArrayList<Person> personArrayList;
    public MyAdapter(Context context, ArrayList<Person> persons){
        this.mcontext = context;
        this.personArrayList = persons;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(),R.layout.person_item,null);
        ViewHolder viewHolder = new ViewHolder(view);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        //Person person = new Person();
        //person = personArrayList.get(position);

        holder.tv_name.setText(personArrayList.get(position).getName());
        holder.tv_date.setText(personArrayList.get(position).getDate());
        Log.i(TAG, "onBindViewHolder: " + holder.tv_name.getText().toString());
    }

    @Override
    public int getItemCount() {
        //Log.d("getItemCount",String.valueOf(personArrayList.size()));
        return personArrayList == null ? 0 : personArrayList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        public TextView tv_name;
        public TextView tv_date;
        public ViewHolder(View view){
            super(view);
            tv_name = (TextView)view.findViewById(R.id.recycler_view_item_person_name);
            tv_date = (TextView)view.findViewById(R.id.recycler_view_item_person_date);
        }
    }
}
